﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using VideoClassLibrary.Model;
using VideoClassLibrary.BusinessLogicLayer;
using System.Data;

public partial class SchoolNoticeManagement_UpdateNotice : AdminUserBase
{
    V_announcement ANCE = new V_announcement();
    AnnouncementModule AM = new AnnouncementModule();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            trc.Visible = false;
            radbtnIsPublish.Enabled = false;
            ShowNewHtml();
            ShowAnnoucementList();
           
        }
    }

    protected void btnAdd_Click(object sender, EventArgs e)
    {
        ANCE = new V_announcement();
        ANCE.Id = Convert.ToInt32(Request.QueryString["Id"]);
        if (AdminType == 4)
        {

            ANCE.IsPublished = 0;
        }
        else
        {
            ANCE.IsPublished = Convert.ToInt32(this.radbtnIsPublish.SelectedValue);
        }
        ANCE.AnnouncementTitle = this.txtAnnouncementTitle.Text.ToString();
        ANCE.AnnouncementContent = this.txtAnnouncementContent.Text.ToString();
        ANCE.SchoolId = this.SchoolID;
        ANCE.CreaterId = this.UserID;
        ANCE.CreaterName = this.RealName;
        ANCE.UpdateTime = DateTime.Now;
        AM.UpdateAnnouncement(ANCE);
        Response.Redirect("SearchNoticeList.aspx");
    }
    private void ShowAnnoucementList()
    {

        ANCE = new V_announcement();
        string Aid=Request.QueryString["Id"];
        DataSet ds = AM.QueryAnnouncement(SchoolID, int.Parse(Aid));
        DataRow dr = ds.Tables[0].Rows[0];
        this.txtAnnouncementTitle.Text = dr["AnnouncementTitle"].ToString();
        this.txtAnnouncementContent.Text = dr["AnnouncementContent"].ToString();
        if (AdminType == 4)
        {
            this.radbtnIsPublish.SelectedValue ="0";
        }
        else
        {
            this.radbtnIsPublish.SelectedValue = dr["IsPublished"].ToString();
        }
    }

    private void ShowNewHtml()
    {
        DataSet ds = new DataSet();
        AdminModule am = new AdminModule();
        string typeva = AdminType.ToString();
        ds = am.GetAdmin(-1, typeva);
        DataRow dr = ds.Tables[0].Rows[0];
        int result = Convert.ToInt32(dr["VA_type"]);
        if (result != 4)
        {
            trc.Visible = true;
            radbtnIsPublish.Enabled = true;
        }

    }
}
